﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Betop.Lib.Core.Base;
using Betop.Lib.Enums;
using Betop.Lib.Utilities;

namespace Betop.Lib.Core.Attach
{
   
    public class AttachDAL:BaseDAL
    {
        private string _tableName;
        public AttachDAL(TableName tableName)
        {
            this._tableName = tableName.ToString();
        }
        public AttachDAL(string tableName)
        {
            _tableName = tableName;
        }

        internal List<AttachInfo> GetList(int bindID)
        {
            string sql = "select * from " + _tableName + " where BindID = " + bindID + " order by InputTime desc";
            List<AttachInfo> list = dbOper.Query<AttachInfo>(sql);
            return list;
        }

        internal List<AttachInfo> GetList(List<int> lstBindIDs)
        {
            string sql = "select * from " + _tableName + " where BindID in (" + ConvertUtil.ConvertToDbStr(lstBindIDs) + ") order by InputTime desc";
            List<AttachInfo> list = dbOper.Query<AttachInfo>(sql);
            return list;
        }

        internal List<AttachInfo> GetListByIDs(List<int> lstAttachIDs)
        {
            string ids = ConvertUtil.ConvertToDbStr(lstAttachIDs);
            string sql = "select * from " + _tableName + " where ID in (" + ids + ")";
            List<AttachInfo> list = dbOper.Query<AttachInfo>(sql);
            return list;
        }

        internal List<int> GetIDs(object bindID)
        {
            string sql = "select ID from " + _tableName + " where BindID=@p0";
            List<int> ids = dbOper.Query<int>(sql, bindID);
            return ids;
        }
    }
}
